
package node;

/**
 * This static class is used to do type conversion works. And also check the
 * validity.
 * 
 * @author Team 6
 * @version 598
 */
public final class Conversion
{

  /**
   * private constructor.
   */
  private Conversion()
  {
    // do nothing.
  }

  /**
   * Convert the node id to integer.
   * 
   * @param the_node is the node id that in a form as "node_id_"
   * @return the id of "the_node_id".
   */
  public static int StringToInt(final String the_node)
  {
    int id = 0;
    try
    {
      final String temp = the_node.substring(the_node.lastIndexOf('_') + 1);
      id = Integer.parseInt(temp);
    }
    catch (final NumberFormatException e)
    {
      System.err.println("Problem happens on getting node id of " + the_node);
      id = -1;
    }
    return id;
  }

  /**
   * Convert node id to string as format "node_id_".
   * 
   * @param the_id is the node id.
   * @return the string of the node id.
   */
  public static String IntToString(final int the_id)
  {
    return "node_id_" + the_id;
  }

}
